﻿Namespace Core

    ''' <summary>
    ''' Helper function set
    ''' </summary>
    ''' <remarks></remarks>
    Friend NotInheritable Class Helper

        ''' <summary>
        ''' Converts an epoch-date to a .NET Datetime Value
        ''' </summary>
        ''' <param name="value"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function EPOCHToDateTime(ByVal value As Integer) As DateTime
            Return New DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(value)
        End Function
        ''' <summary>
        ''' Converts an a .NET Datetime Value to  epoch-date
        ''' </summary>
        ''' <param name="value"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function DateTimeToEPOCH(ByVal value As DateTime) As Integer
            Return value.Subtract(New DateTime(1970, 1, 1, 0, 0, 0)).Seconds
        End Function

        ''' <summary>
        ''' Converts a normal string to a utf 8 string
        ''' </summary>
        ''' <param name="input"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function ConvertToUTF8String(ByVal input As String) As String
            Dim b() As Byte = System.Text.Encoding.UTF8.GetBytes(input)
            Return System.Text.Encoding.Default.GetString(b)
        End Function
        ''' <summary>
        ''' Escape the given input
        ''' </summary>
        ''' <param name="input"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function EscapeUriString(ByVal input As String) As String
            Return Uri.EscapeUriString(input)
        End Function

        ''' <summary>
        ''' Returns then encoded url from input
        ''' </summary>
        ''' <param name="input">web address (e.g. http://www.yourdomain.net/yourCustomApplication.php)</param>
        ''' <returns>encoded string (e.g. http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php)</returns>
        ''' <remarks></remarks>
        Public Shared Function UrlEncode(ByVal input As String) As String
            Return System.Web.HttpUtility.UrlEncode(input)
        End Function

    End Class

End Namespace